package com.globalresources.ui.struts.action.authority;

import java.util.Collection;
import com.globalresources.business.inface.IAuthorityService;
import com.globalresources.commons.AbstractAction;
import com.globalresources.commons.Pager;
import com.globalresources.commons.PagerService;
import com.globalresources.commons.StringHelper;
import com.globalresources.po.Authority;


/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 7, 2009 3:35:30 AM
 */
public class AuthorityAction extends AbstractAction{
	
	private static final long serialVersionUID = 1L;
	private PagerService pagerService;
	private IAuthorityService authorityService;
	private Pager pager;
	private Authority myAuthority;
	private String authorityId;
	protected java.util.List<Authority> Authorities;
	protected String pagerMethod;
	protected String totalRow;
	protected String currentPage;
	protected String authority;
	
	public String load(){
		if (StringHelper.isNotEmpty(authorityId)) {
			setMyAuthority(authorityService.getAuthority(new Integer(authorityId)));
		}else {
			setMyAuthority(null);
		}
		return SUCCESS;
	}
	
	public String list() throws Exception{
		int _totalRow = authorityService.countAuthorities(authority);
		pager=pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), _totalRow);
		this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
		this.setTotalRow(String.valueOf(_totalRow));
		Authorities = authorityService.getAuthorities(authority, pager.getPageSize(), pager.getStartRow());
		return SUCCESS;
	}
	
	public String save()throws Exception{
		Integer id = this.myAuthority.getId();
		if (null!=id) {
			authorityService.updateAuthority(myAuthority);
		}else{
			authorityService.saveAuthority(myAuthority);
		}
		return SUCCESS;
	}
	
	public String delete(){
		if (StringHelper.isNotEmpty(authorityId)) {
			Authority delete_authority = authorityService.getAuthority(new Integer(authorityId));
			if (null != delete_authority) {
				authorityService.deleteAuthority(delete_authority);
			}
		}		
		return SUCCESS;
	}


	public PagerService getPagerService() {
		return pagerService;
	}


	public void setPagerService(PagerService pagerService) {
		this.pagerService = pagerService;
	}


	public IAuthorityService getAuthorityService() {
		return authorityService;
	}


	public void setAuthorityService(IAuthorityService authorityService) {
		this.authorityService = authorityService;
	}


	public Pager getPager() {
		return pager;
	}


	public void setPager(Pager pager) {
		this.pager = pager;
	}


	public String getPagerMethod() {
		return pagerMethod;
	}


	public void setPagerMethod(String pagerMethod) {
		this.pagerMethod = pagerMethod;
	}


	public String getTotalRow() {
		return totalRow;
	}


	public void setTotalRow(String totalRow) {
		this.totalRow = totalRow;
	}


	public String getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}


	public String getAuthority() {
		return authority;
	}


	public void setAuthority(String authority) {
		this.authority = authority;
	}

	public Authority getMyAuthority() {
		return myAuthority;
	}

	public void setMyAuthority(Authority myAuthority) {
		this.myAuthority = myAuthority;
	}

	public java.util.List<Authority> getAuthorities() {
		return Authorities;
	}

	public void setAuthorities(java.util.List<Authority> authorities) {
		Authorities = authorities;
	}

	public String getAuthorityId() {
		return authorityId;
	}

	public void setAuthorityId(String authorityId) {
		this.authorityId = authorityId;
	}
	
}
